//
//  TotalAddressViewController.m
//  SDHuiYuShoping
//
//  Created by luojiao on 2017/5/9.
//  Copyright © 2017年 luojiao. All rights reserved.
//

#import "TotalAddressViewController.h"
#import "UIViewController+KNSemiModal.h"
#import "ChooseProvinceVC.h"

@interface TotalAddressViewController ()

{
    NSMutableArray *addresArr;
}
@end

@implementation TotalAddressViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    addresArr = [[NSMutableArray alloc] initWithObjects:@"山东省烟台市芝罘区鲁东国际21楼",@"山东省烟台市芝罘区医院", nil];
    
    
    [_bacButton setImage:[UIImage imageNamed:@"close_btn"] forState:UIControlStateNormal];
    [_bacButton setImageEdgeInsets:UIEdgeInsetsMake(-40, 0, 0, -80)];
    
    _tableView.separatorStyle = NO;
}

- (void)viewWillAppear:(BOOL)animated
{
    [super viewWillAppear:animated];
    self.navigationController.navigationBar.hidden = YES;
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

#pragma mark - UITableViewDelegate,UITableViewDataSource

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return addresArr.count;
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    return 80;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString *identfier = @"totalCell";
    TotalAddressTableViewCell *cell;
    cell = [tableView dequeueReusableCellWithIdentifier:identfier];
    if (!cell)
    {
        cell = [[NSBundle mainBundle] loadNibNamed:@"TotalAddressTableViewCell" owner:self options:nil][0];
    }
    cell.delegate = self;
    
    cell.addressName.text = [addresArr objectAtIndex:indexPath.row];
    //cell 没有选中状态
    cell.selectionStyle = UITableViewCellSelectionStyleNone;
    return cell;
}


#pragma mark - ButtonClick

- (IBAction)bacButton:(id)sender {
    
     [self closeViewController];
}

- (IBAction)addAddressButton:(id)sender
{
    ChooseProvinceVC *chosseProvince = [[ChooseProvinceVC alloc] init];
    [self.navigationController pushViewController:chosseProvince animated:YES];
    
}

#pragma mark - TotalChooseButtonDelegate

-(void)totalChooseButton:(TotalAddressTableViewCell *)cell
{
    cell.chosseButton.selected =! cell.chosseButton.selected;
    if (cell.chosseButton.selected)
    {
        [cell.chosseButton setImage:[UIImage imageNamed:@"select_btn_sel"] forState:UIControlStateNormal];
    }
    else
    {
        [cell.chosseButton setImage:[UIImage imageNamed:@"select_btn"] forState:UIControlStateNormal];
    }
}



//弹出半截页面的页面回收方法
- (void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event
{
    [self closeViewController];
}

- (void)closeViewController {
    
    UIViewController * parent = [self.view containingViewController];
    if ([parent respondsToSelector:@selector(dismissSemiModalView)]) {
        [parent dismissSemiModalView];
    }
    
}




/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
